//
//  OwnerActController.m
//  UI16.真.豆瓣
//
//  Created by dllo on 15/11/5.
//  Copyright © 2015年 Amydom. All rights reserved.
//

#import "OwnerActController.h"
#import "OwnerActCell.h"
#import "LoginViewController.h"
#import "LoginView.h"
#import "SingLeton.h"
#import "ActDetailViewController.h"
@interface OwnerActController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic ,retain)UITableView *myTable;
@property (nonatomic , retain)LoginView *login;
@property (nonatomic ,retain)NSMutableArray *array;


@end

@implementation OwnerActController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"我的活动";
    self.myTable = [[UITableView alloc]initWithFrame:[[UIScreen mainScreen]bounds] style:UITableViewStylePlain];
    [self.view addSubview:self.myTable];
    self.myTable.delegate = self;
    self.myTable.dataSource = self;
    [self.myTable registerClass:[OwnerActCell class] forCellReuseIdentifier:@"cell"];
    [_myTable release];
//    self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"登陆" style:UIBarButtonItemStylePlain target:self action:@selector(RightAction:)] autorelease];
//    self.navigationItem.rightBarButtonItem.tintColor = [UIColor blackColor];
    
    self.array = [NSMutableArray array];
    
    //去掉多余的cell
    self.myTable.tableFooterView = [UIView new];
    

}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *cellIndentifier = @"cell";
    OwnerActCell *cell =[tableView dequeueReusableCellWithIdentifier:cellIndentifier];
    NSString *name = [[NSUserDefaults standardUserDefaults]objectForKey:@"name"];
    self.array = [[SingLeton shareSingleton]selectActName:name];
    NSString *title = [self.array objectAtIndex:indexPath.row];
    cell.textLabel.text = title;
    
    
    
    
    
    return cell;
    
    
    
}



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    ActDetailViewController *actDV = [[ActDetailViewController alloc]init];
    
    // 取消置灰
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    NSMutableArray *array = [[SingLeton shareSingleton]selectActName:[self.array objectAtIndex:indexPath.row]];
    
    actDV.activityList = [array lastObject];
      [self.navigationController pushViewController: actDV animated:YES];
    
    
    
    
}

//编辑每行的删除样式
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return UITableViewCellEditingStyleDelete;
    
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
     NSString *name = [[NSUserDefaults standardUserDefaults]objectForKey:@"name"];
    //如果是进行删除操作
    if (editingStyle == UITableViewCellEditingStyleDelete) {
      //根据row删除学生对象
        [[SingLeton shareSingleton]deleteActivityCollect:[self.array objectAtIndex:indexPath.row] userName:name];
        [self.array removeObjectAtIndex:indexPath.row];
        
        
        
        
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath, nil] withRowAnimation:UITableViewRowAnimationMiddle];
        
        
    }
    
    
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
